#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    bool hasAlternatingBits(int n) {
        int count = 0;
        while (n > pow(2, count++));
        for (int i = 1; i < count - 1; ++i)
        {
            if (((n >> i) & 1) == ((n >> (i - 1)) & 1))
                return false;
        }

        return true;
    }
};